/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.digitalization.controller;

import cn.hutool.core.lang.Pair;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.modules.digitalization.service.IUmsUserInfoService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 档案表-java 控制器
 *
 * @author RS
 * @since 2023-01-07
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("blade-archives/archives")
@Api(value = "档案表-java", tags = "档案表-java接口")
public class ManageArchivesController extends BladeController {

	private final IUmsUserInfoService umsUserInfoService;

	@PostMapping("/import")
	public R<String> importZip(MultipartFile file, @RequestParam String a0201b, @RequestParam(defaultValue = "false") Boolean cover) {
		try {
			R<String> stringR = umsUserInfoService.doImportZip(file, a0201b, cover);
			return stringR;
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			return R.fail(e.getMessage());
		}
	}

	@GetMapping("/import/restore")
	public R<String> importZipFormStore(@RequestParam String filePath, @RequestParam String a0201b, @RequestParam(defaultValue = "false") Boolean cover) {
		return umsUserInfoService.doImportDir(filePath, a0201b, cover);
	}

	@GetMapping("/import/check")
	public R<String> importZipCheck(String hash) {
		Pair<Boolean, String> fileUploaded = umsUserInfoService.isFileUploaded(hash);
		return R.data(fileUploaded.getValue());
	}

}
